package com.twu.biblioteca;

import java.util.Map;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: Joe
 * Date: 8/07/13
 * Time: 2:06 PM
 * To change this template use File | Settings | File Templates.
 */
public final class User {

    public final String userID;
    public final String password;
    public final String name;
    public final String email;
    public final String phone;

    public static Map<String, User> users = new HashMap<String,User>();
    static
    {
        users.put("111-1111",new User("111-1111","1111","Joe","joe@test.com","0312345678"));
        users.put("111-1112",new User("111-1112","2222","Lucy","lucy@test.com","0391235477"));
        users.put("111-1113",new User("111-1113","3333","David","davo@test.com","0334512147"));
        users.put("111-1114",new User("111-1114","4444","Lauren","lozza@test.com","0396545123"));
        users.put("111-1115",new User("111-1115","5555","Steven","stevo@test.com","0354544412"));
        users.put("111-1116",new User("111-1116","6666","Lafaunda","lafonda@test.com","0332212487"));
        users.put("111-1117",new User("111-1117","7777","James","jimmy@test.com","0454414141"));
        users.put("111-1118",new User("111-1118","8888","Kristy","krissy@test.com","035454545"));
        users.put("111-1119",new User("111-1119","9999","Ben","ben@test.com","0398554545"));
        users.put("111-1120",new User("111-1120","0000","Alicia","alz@test.com","0312312122"));
    }

    public User(String userID, String password, String name, String email, String phone)
    {
        this.userID = userID;
        this.password = password;
        this.name = name;
        this.email = email;
        this.phone = phone;
    }

    public static User getUser(String userID, String password) throws UserNotFoundException
    {
        User user = users.get(userID);

        if(user != null && user.password.equals(password))
            return user;
        else
            throw new UserNotFoundException("User " + userID + " not found.");
    }

    @Override
    public String toString()
    {
        return "Name:" +this.name +" Email:" + this.email + " Phone:" + this.phone;
    }

    public static class UserNotFoundException extends Exception
    {
        public UserNotFoundException() {}

        //Constructor that accepts a message
        public UserNotFoundException(String message)
        {
            super(message);
        }
    }
}
